﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Faker {
    public static class InternetFaker {
        
        public static string FreeEmail(string name) {
            var domains = new[] {"gmail.com", "yahoo.com", "hotmail.com"};
            return UserName(name) + "@" + domains.Random();
        }

        public static string Email(string name) {
            return UserName(name) + "@" + DomainName();
        }

        public static string UserName(string name) {
            if (!string.IsNullOrEmpty(name)) {
                var separator = (new[] {".", "_"}).Random();
                return string.Join(separator, name.Split(" ".ToCharArray()).Shuffle()).ToLower();
            }

            var formats = new[] {
                                    NameFaker.FirstName().Replace(" ", "").ToLower(),
                                    NameFaker.FirstName().First() + NameFaker.LastName().Replace(" ", "").ToLower()
                                };
            return formats.Random();
        }

        public static string DomainName() {
            return DomainWord() + "." + DomainSuffix();
        }

        private static string DomainWord() {
            return CompanyFaker.Name().Split(" ".ToCharArray()).First().Replace(" ", "").ToLower();
        }

        private static string DomainSuffix() {
            var suffixes = new[] {"co.uk", "com", "us", "uk", "ca", "biz", "info", "name", "com.ar", "com.br"};
            return suffixes.Random();
        }

        public static string IPAddress() {
            var random = new Random();
            return random.Next(255) + "." + random.Next(255) + "." + random.Next(255) + "." + random.Next(255);
        }
    }
}
